# Maintainer: Andreas Radke <andyrtr at archlinux.org>
# Contributor: Thomas Baechler <thomas.baechler@rwth-aachen.de>

pkgname=cups-pdf
pkgver=3.0.1
pkgrel=8
pkgdesc="PDF printer for cups"
arch=(loong64 x86_64)
depends=('cups' 'ghostscript')
install=cups-pdf.install
url="https://www.cups-pdf.de/welcome.shtml"
license=('GPL2')
options=('debug')
source=(https://www.cups-pdf.de/src/cups-pdf_$pkgver.tar.gz
        remove-deprecated-ghostscript-setpdfwrite-operator.diff)
backup=(etc/cups/cups-pdf.conf)
# http://www.cups-pdf.de/src/cups-pdf_3.0.1.tar.gz.md5 - no other checksums
md5sums=('5071bf192b9c6eb5ada4337b6917b939'
         '08eb1f7037ec8c6197437204d533db22')
sha256sums=('738669edff7f1469fe5e411202d87f93ba25b45f332a623fb607d49c59aa9531'
            '8429e8329ac8b10dd28bd1f5693cf3b0eb7461a62183440c319430c999ab8cbd')

prepare() {
  cd "$pkgname-$pkgver"
  # remove unsupported ghostscript operator - FS#70313
  patch -Np1 -i ../remove-deprecated-ghostscript-setpdfwrite-operator.diff
}  

build() {
  cd "$pkgname-$pkgver"/src
  [ -z "$CC" ] && CC=gcc
#  $CC $CFLAGS -Wall -o cups-pdf cups-pdf.c
  $CC $CFLAGS $LDFLAGS -s cups-pdf.c -o cups-pdf -lcups  
}

package() {
  cd "$pkgname-$pkgver"/src
  install -D -m700 cups-pdf "$pkgdir"/usr/lib/cups/backend/cups-pdf

  # Install Postscript Color printer
  cd ../extra
  install -D -m644 CUPS-PDF_noopt.ppd "$pkgdir"/usr/share/cups/model/CUPS-PDF_noopt.ppd
  install -D -m644 CUPS-PDF_opt.ppd "$pkgdir"/usr/share/cups/model/CUPS-PDF_opt.ppd

  # Install config file
  install -D -m644 cups-pdf.conf "$pkgdir"/etc/cups/cups-pdf.conf

  # Install docs
  install -D -m 644 ../README "$pkgdir"/usr/share/doc/$pkgname/README
  
  # use cups group from cups pkg FS#57311/FS#56818/FS#57313
  chgrp -R cups "${pkgdir}"/etc/cups
  sed -i "s:### Default\: lp:### Default\: cups:" "${pkgdir}"/etc/cups/cups-pdf.conf
  sed -i "s:#Grp lp:Grp cups:" "${pkgdir}"/etc/cups/cups-pdf.conf
}
